package com.kingsoft.dc.khaos.plugin.core.utils;

import java.io.UnsupportedEncodingException;
import java.util.Base64;

/**
 * Created by jing on 19/8/10.
 */
public class Base64CodeUtils {

    public static String encode(String text) {
        final Base64.Encoder encoder = Base64.getEncoder();
        final byte[] textByte;
        String encodedText = null;
        try {
            textByte = text.getBytes("UTF-8");
            //编码
            encodedText = encoder.encodeToString(textByte);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return encodedText;

    }

    public static String decode(String encodedText) {
        String text = null;
        try {
            final Base64.Decoder decoder = Base64.getDecoder();
            //解码
            text = new String(decoder.decode(encodedText), "UTF-8");

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return text;
    }
}

